﻿<!DOCTYPE html>
<!--
Item Name: Elisyam - Web App & Admin Dashboard Template
Version: 1.3
Author: SAEROX

** A license must be purchased in order to legally use this template for your project **
-->
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>系统登陆</title>
        <meta name="description" content="Elisyam is a Web App and Admin Dashboard Template built with Bootstrap 4">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
        <!-- Google Fonts -->
        <script src="https://cdn.bootcss.com/webfont/1.6.26/webfontloader.js"></script>
        <script>
          WebFont.load({
            google: {"families":["Montserrat:400,500,600,700","Noto+Sans:400,700"]},
            active: function() {
                sessionStorage.fonts = true;
            }
          });
        </script>
        <!-- Favicon -->
        <link rel="apple-touch-icon" sizes="180x180" href="__STATIC__/img/apple-touch-icon.png">
        <link rel="icon" type="image/png" sizes="32x32" href="__STATIC__/img/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="__STATIC__/img/favicon-16x16.png">
        <!-- Stylesheet -->
        <link rel="stylesheet" href="__STATIC__/vendors/css/base/bootstrap.min.css">
        <link rel="stylesheet" href="__STATIC__/vendors/css/base/elisyam-1.2.css">
        <style type="text/css">
            .loginfooter{
                position:absolute;
                bottom:40px;
                right:40px;
            }
        </style>
        
        <!-- Tweaks for older IEs--><!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
        <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]-->
    </head>
    <body class="bg-white">
        <!-- Begin Preloader -->
        <div id="preloader">
            <div class="canvas">
                <img src="__STATIC__/img/logo.png" alt="logo" class="loader-logo">
                <div class="spinner"></div>   
            </div>
        </div>
        <!-- End Preloader -->
        <!-- Begin Container -->
        <div class="container-fluid no-padding h-100">
            <div class="row flex-row h-100 bg-white">
                <!-- Begin Left Content -->
                <div class="col-xl-3 col-lg-5 col-md-5 col-sm-12 col-12 no-padding">
                    <div class="elisyam-bg background-03">
                        <div class="elisyam-overlay overlay-08"></div>
                        <div class="authentication-col-content-2 mx-auto text-center">
                            <div class="logo-centered">
                                <a href="db-default.html">
                                    <img src="__STATIC__/img/logo.png" alt="logo">
                                </a>
                            </div>
                            <h1>开始你的工作!</h1>
                            <span class="description">
                                良好的数据记录是一切工作的基础</br>辛苦你了!
                            </span>
                            <ul class="login-nav nav nav-tabs mt-5 justify-content-center" role="tablist" id="animate-tab">
                                <li><a class="active" data-toggle="tab" href="#singin" role="tab" id="singin-tab" data-easein="zoomInUp">库存查询</a></li>
                                <li><a data-toggle="tab" href="#signup" role="tab" id="signup-tab" data-easein="zoomInRight">系统登陆</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- End Left Content -->
                <!-- Begin Right Content -->
                <div class="col-xl-9 col-lg-7 col-md-7 col-sm-12 col-12 my-auto no-padding">
                    <!-- Begin Form -->
                    <div class="authentication-form-2 mx-auto">
                        <div class="tab-content" id="animate-tab-content">
                            <!-- Begin Sign In -->
                            <div role="tabpanel" class="tab-pane show active" id="singin" aria-labelledby="singin-tab">
                                <h3>库存查询</h3>
                                <form id="query" action="{:url('login/loginCheck')}" >
                                    <div class="group material-input">
        							    <input type="number" step="1" required name="queryPassword" id='queryPassword' maxlength="7">
        							    <span class="highlight"></span>
        							    <span class="bar"></span>
        							    <label>输入查询码</label>
                                    </div>
                                    <div class="sign-btn text-center">
                                        <button class="btn btn-lg btn-gradient-01" type="button" onclick="queryInter()">
                                            登陆
                                        </button>
                                    </div>
                                </form>
                            </div>
                            <!-- End Sign In -->
                            <!-- Begin Sign Up -->
                            <div role="tabpanel" class="tab-pane" id="signup" aria-labelledby="signup-tab">
                                <h3>工作系统登陆</h3>
                                <form id="login" action="{:url('login/loginCheck',['type'=>'login'])}" >
                                    <div class="group material-input">
                                        <input type="text" required name="phone">
                                        <span class="highlight"></span>
                                        <span class="bar"></span>
                                        <label>手机</label>
                                    </div>
                                    <div class="group material-input">
                                        <input type="password" required name="password">
                                        <span class="highlight"></span>
                                        <span class="bar"></span>
                                        <label>密码</label>
                                    </div>
                                    <div class="sign-btn text-center">
                                        <button class="btn btn-lg btn-gradient-01" type="submit">
                                            登陆
                                        </button>
                                    </div>
                                </form>
                            </div>
                            <!-- End Sign Up -->
                        </div>
                    </div>
                    <!-- End Form -->                        
                </div>
                <!-- End Right Content -->
            </div>
            <div class="loginfooter">
                广西长道汽车销售服务有限公司桂林分公司 <a href="http://beian.miit.gov.cn">桂ICP备19009679号-1</a>
            </div>
            <!-- End Row -->
        </div>
        <!-- End Container -->   
        <!-- Begin Vendor Js -->
        <script src="__STATIC__/vendors/js/base/jquery.min.js"></script>
        <script src="__STATIC__/vendors/js/base/bootstrap.min.js"></script>
        <!-- End Vendor Js -->
        <!-- Begin Page Vendor Js -->
        <script src="__STATIC__/vendors/js/app/app.min.js"></script>
        <!-- End Page Vendor Js -->
        <!-- Begin Page Snippets -->
        <script src="__STATIC__/vendors/js/nicescroll/nicescroll.min.js"></script>
        <script src="__STATIC__/js/components/tabs/animated-tabs.min.js"></script>
        <script src="__STATIC__/vendors/js/noty/noty.min.js"></script> 
        <script src="__STATIC__/vendors/js/jquery.form/jquery.form.min.js"></script>
        <!-- End Page Snippets -->
        <script type="text/javascript">
            $(document).ready(function () {
                //提交登陆表格
                $("#login").ajaxForm({
                    //定义返回JSON数据，还包括xml和script格式
                    dataType : 'json',
                    method : "post",
                    //在发送之前进行的操作，如果有问题，返回false即可不会进行提交
                    beforeSend: function () {
                        //定义 form为当前表格
                        const form = $("#login")

                        //如果没有完成校验就返回false不提交
                        if (form[0].checkValidity() === false){
                            return false;
                        }
                    },
                    success: function (data) {
                        
                        if(!data.user){
                            //提交成功后调用
                            new Noty({
                                type: "error",
                                layout: "topRight",
                                text: "用户名错误",
                                progressBar: true,
                                timeout: 2500,
                                animation: {
                                    open: "animated bounceInRight",
                                    close: "animated bounceOutRight"
                                }
                            }).show();
                            return false;
                        }else if(!data.session){
                            //提交成功后调用
                            new Noty({
                                type: "error",
                                layout: "topRight",
                                text: "设置session失败",
                                progressBar: true,
                                timeout: 2500,
                                animation: {
                                    open: "animated bounceInRight",
                                    close: "animated bounceOutRight"
                                }
                            }).show();
                            return false;
                        }else{
                            //登陆成功后跳转
                            $(location).attr('href', data.link);
                            return false;
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){  
                        //提交成功后调用
                        new Noty({
                            type: "error",
                            layout: "topRight",
                            text: "登陆页面错误",
                            progressBar: true,
                            timeout: 2500,
                            animation: {
                                open: "animated bounceInRight",
                                close: "animated bounceOutRight"
                            }
                        }).show();
                        return false;
                    } 
                });

                //提交登陆表格
                $("#query").ajaxForm({
                    //定义返回JSON数据，还包括xml和script格式
                    dataType : 'json',
                    method : "post",
                    //在发送之前进行的操作，如果有问题，返回false即可不会进行提交
                    beforeSend: function () {
                        //定义 form为当前表格
                        const form = $("#login")

                        //如果没有完成校验就返回false不提交
                        if (form[0].checkValidity() === false){
                            return false;
                        }
                    },
                    success: function (data) {
                        if(!data.user){
                            //提交成功后调用
                            new Noty({
                                type: "error",
                                layout: "topRight",
                                text: "用户名或密码错误",
                                progressBar: true,
                                timeout: 2500,
                                animation: {
                                    open: "animated bounceInRight",
                                    close: "animated bounceOutRight"
                                }
                            }).show();
                            return false;
                        }else if(!data.session){
                            //提交成功后调用
                            new Noty({
                                type: "error",
                                layout: "topRight",
                                text: "设置session失败",
                                progressBar: true,
                                timeout: 2500,
                                animation: {
                                    open: "animated bounceInRight",
                                    close: "animated bounceOutRight"
                                }
                            }).show();
                            return false;
                        }else{
                            //登陆成功后跳转
                            $(location).attr('href', data.link);
                            return false;
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){  
                        //提交成功后调用
                        new Noty({
                            type: "error",
                            layout: "topRight",
                            text: "登陆页面错误",
                            progressBar: true,
                            timeout: 2500,
                            animation: {
                                open: "animated bounceInRight",
                                close: "animated bounceOutRight"
                            }
                        }).show();
                        return false;
                    } 
                });
            });

            function queryInter(){
                var name = $("#queryPassword").val();
                if(name == ""){
                    //提交成功后调用
                    new Noty({
                        type: "error",
                        layout: "topRight",
                        text: "请输入库存查询密码！",
                        progressBar: true,
                        timeout: 2500,
                        animation: {
                            open: "animated bounceInRight",
                            close: "animated bounceOutRight"
                        }
                    }).show();
                    return false;
                }else{
                    var password = $("#queryPassword").val();
                    var url = '{:url('login/loginCheck')}?type=query&queryPassword='+password;
                    $.ajax({
                        url: url,
                        type: 'POST',
                        dataType: 'json'
                    })
                    .done(function(data) {
                        if(!data.user){
                            //提交成功后调用
                            new Noty({
                                type: "error",
                                layout: "topRight",
                                text: "用户名或密码错误",
                                progressBar: true,
                                timeout: 2500,
                                animation: {
                                    open: "animated bounceInRight",
                                    close: "animated bounceOutRight"
                                }
                            }).show();
                            return false;
                        }else if(!data.session){
                            //提交成功后调用
                            new Noty({
                                type: "error",
                                layout: "topRight",
                                text: "设置session失败",
                                progressBar: true,
                                timeout: 2500,
                                animation: {
                                    open: "animated bounceInRight",
                                    close: "animated bounceOutRight"
                                }
                            }).show();
                            return false;
                        }else{
                            //登陆成功后跳转
                            $(location).attr('href', data.link);
                            return false;
                        }
                    })
                    .fail(function(data) {
                        console.log(data);
                    })
                    .always(function(data) {
                        console.log(data);
                    });
                    
                }
            }
        </script>
    </body>
</html>